import {Component, ViewChild} from '@angular/core';
import {GnJsonTableComponent} from 'geminis-ng';
import {NzTreeNode} from 'ng-zorro-antd/tree';

@Component({
  selector: 'everydata-table-list',
  template: `
    <everydata-category-tree (treeInitialed)="loadData($event)" (treeClick)="loadData($event)">
      <gn-json-table url="/everydata-pc/assets/forms/table/table.json"></gn-json-table>
    </everydata-category-tree>
  `
})
export class TableListComponent {

  @ViewChild(GnJsonTableComponent, {static: true}) table!: GnJsonTableComponent;
  category?: string;

  loadData(nodes: NzTreeNode[]): void {
    if (nodes.length === 0 || !this.table.config) {
      return;
    }
    const node = nodes[0];
    this.category = node.origin.data.id;
    this.table.config.buttons!.newForm!.params = {categoryId: this.category};
    this.table.config.filterGroup.filters[0].value = node.origin.data.pathId + '%';

    this.table.table.loadDataAndCleanSelection();
  }

}

